﻿Imports Microsoft.VisualBasic

Namespace My
    Public Class MyDropDownList
        Inherits DropDownList

        Protected Overrides Sub OnDataBound(ByVal e As System.EventArgs)
            If Me.AppendPleaseChooseItem = True Then
                Me.Items.Insert(0, MyObj.GetDDLPleaseChooseItem())
            End If

            If Me.AppendSelectAllItem = True Then
                Me.Items.Insert(0, MyObj.GetDDLSelectAllItem())
            End If

            MyBase.OnDataBound(e)
        End Sub

        Public Property AppendSelectAllItem() As Boolean
            Get
                If ViewState("AppendSelectAllItem") Is Nothing Then
                    Return False
                End If

                Return ViewState("AppendSelectAllItem")
            End Get
            Set(ByVal value As Boolean)
                ViewState("AppendSelectAllItem") = value
            End Set
        End Property

        Public Property AppendPleaseChooseItem() As Boolean
            Get
                If ViewState("AppendPleaseChooseItem") Is Nothing Then
                    Return False
                End If

                Return ViewState("AppendPleaseChooseItem")
            End Get
            Set(ByVal value As Boolean)
                ViewState("AppendPleaseChooseItem") = value
            End Set
        End Property

        'Protected Overrides Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NameValueCollection) As Boolean
        '    Dim values As String() = postCollection.GetValues(postDataKey)
        '    Dim selectedValue = values(0)

        '    Me.PreviousSelectedValue = selectedValue

        '    Return MyBase.LoadPostData(postDataKey, postCollection)
        'End Function

        'Public Property PreviousSelectedValue() As String
        '    Get
        '        Return ViewState("PreviousSelectedValue")
        '    End Get
        '    Set(ByVal value As String)
        '        ViewState("PreviousSelectedValue") = value
        '    End Set
        'End Property
    End Class
End Namespace
